﻿<?php
require('common_view_functions.php');

function build_tag_cloud($coll_tags, $blg_uri) {
	$str_tag_cloud = '';
	foreach($coll_tags as $tg) {
		$str_tag_cloud .= '<a href="/' . $blg_uri . '/tag/' . urlencode($tg->tag_text) . '"><span class="tagl_' . $tg->tag_level . '">' . htmlspec($tg->tag_text) . '</span></a> ';
	}
	return $str_tag_cloud;
}

/*
function blogging_since($coll_arc) {
	if(count($coll_arc) < 1) {
		return '';
	} else {
		$firstMonth = $coll_arc[count($coll_arc) - 1];
		return '始于' . $firstMonth->year . '年' . $firstMonth->month . '月；';
	}
}
*/

$show_my_emotag = FALSE;
// emoTag wrapper proc
if(strpos($blog_info->announcement, '[emoTag]') !== FALSE) {
	$ett = '<div id="emoTagsWrapper"></div>';
	$ett .= '<div id="emoTagPagingPanel">';
	$ett .= '<a href="javascript:;" rel="prev">&laquo;</a>';
	$ett .= '<span>Loading...</span>';
	$ett .= '<a href="javascript:;" rel="next">&raquo;</a>';
	$ett .= '</div>';
	$blog_info->announcement = str_replace('[emoTag]', $ett, $blog_info->announcement);
	$show_my_emotag = TRUE;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><?php echo(htmlspec($blog_info->title)); ?></title>

<link rel="shortcut icon" href="/img/favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0: Posts" href="<?php echo('/' . $blogger_uri); ?>/rss" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0: Comments" href="<?php echo('/' . $blogger_uri); ?>/rss_comment" />

<link rel="stylesheet" type="text/css" href="/css/themes/<?php echo($blog_info->skin_name); ?>/styles.css" />
<link rel="stylesheet" type="text/css" href="/css/3rd/jqModal.css" />
<link rel="stylesheet" type="text/css" href="/css/expressions.css" />
<link rel="stylesheet" type="text/css" href="/css/tags.css" />
<link rel="stylesheet" type="text/css" href="/css/emotag.css" />
<link rel="stylesheet" type="text/css" href="/css/widgets.css" />
<link rel="stylesheet" type="text/css" href="/css/ubb_more.css" />
</head>

<body>
<?php require('ie_warning.php') ?>
<div id="wrapper">
	<!-- header -->
	<?php require('common_header.php'); ?>
	<!-- /header -->
	
	<div id="body">
		<div id="main">
			<!-- entries -->
			<div id="entries">
				
				<?php foreach($recent_entries as $entry) { ?>
				
				<div class="entry">
					<h3 class="expr_<?php echo($entry->expression); ?>">
						<?php if($entry->id > 0) { ?>
						<a href="<?php echo('/' . $blogger_uri . '/entry/' . $entry->id); ?>"><?php echo(htmlspec($entry->title)); ?></a>
						<?php } else { ?>
						<?php echo($entry->state == 0 ? '保密网志' : '社区内部网志'); ?>
						<?php } ?>
						<span>@ <?php echo(date_part($entry->post_time)); ?></span>
					</h3>
					
					<?php if($current_user_id > 0) { ?>
						<div class="watch"><a href="javascript:;" rel="w_<?php echo($entry->id); ?>"><img alt="关注此帖" src="/img/star.png" title="关注此帖" /></a></div>
					<?php } ?>
					
					<div class="cate">
						<?php if($entry->id > 0) { ?>
						<?php echo(htmlspec($entry->category_title)); ?>
						<?php } else { echo('N/A'); } ?>
					</div>
					
					<div class="content<?php echo(entry_state_indicator($entry->state)); ?>">
						<?php echo($entry->content); ?>
					</div>
					
					<div class="tags">
						<?php echo(make_tag_links($entry->tags, $blogger_uri)); ?>
						<div class="z"></div>
					</div>
					
					<div class="info">
						<?php if($is_blog_owner) { ?>
						<input type="button" id="e_<?php echo($entry->id); ?>" class="editEntryButton" value="编辑" />
						<?php } ?>
						发布于 <?php echo($entry->post_time); ?>
						|
						<?php if($entry->id > 0) { ?>
						<a href="<?php echo('/' . $blogger_uri . '/entry/' . $entry->id . '#comments'); ?>">评论：<strong><?php echo($entry->comment_num); ?></strong></a>
						<?php } else { echo('评论：N/A'); } ?>
					</div>
				</div>
				
				<?php } ?>
				<div id="paging">
					<a href="<?php echo('/' . $blogger_uri . $next_page_url); ?>">下一页 &raquo;</a>
					<a href="<?php echo('/' . $blogger_uri . $prev_page_url); ?>">&laquo; 上一页</a>
					<a href="<?php echo('/' . $blogger_uri); ?>">首页</a>
					<div class="z"></div>
				</div>
			</div>
			<!-- /entries -->
			
			<div id="bottom">
				<div id="tag_cloud">
					<fieldset>
						<legend>Tag 云图</legend>
						<?php echo(build_tag_cloud($tags, $blogger_uri)); ?>
					</fieldset>
				</div>				
				<div class="z"></div>
			</div>

		</div><!-- /main -->
		
		<div id="side">
			
			<div id="ann"><?php echo($blog_info->announcement); ?></div>
			
			<dl class="block">
				<dt>categories</dt>
				<dd>
					<ul>
						<li><a href="<?php echo('/' . $blogger_uri); ?>/rss/1"><img alt="" src="/img/rss_icon_glass12.png" class="rssIconSmall" /></a> <a href="<?php echo('/' . $blogger_uri); ?>/category/1">未分类</a></li>
						<?php foreach($custom_categories as $cate) { ?>
						<li><a href="<?php echo('/' . $blogger_uri . '/rss/' . $cate->id); ?>"><img alt="" src="/img/rss_icon_glass12.png" class="rssIconSmall" /></a> <a href="<?php echo('/' . $blogger_uri . '/category/' . $cate->id); ?>"><?php echo(htmlspec($cate->title)); ?></a></li>
						<?php } ?>
					</ul>
				</dd>
			</dl>
			
			<dl class="block">
				<dt>recent comments</dt>
				<dd>
					<ul id="rcl">
						<?php foreach($recent_comments as $rc) { ?>
							<?php if($rc->id < 0) { ?>
							<li>N/A...</li>
							<?php } else { ?>
							<li><span class="from"><?php echo(htmlspec($rc->author_name)); ?></span>: <a href="<?php echo('/' . $blogger_uri . '/entry/' . $rc->entry_id . '#c' . $rc->id); ?>"><?php echo(htmlspec($rc->content)); ?></a></li>
							<?php } ?>
						<?php } ?>
					</ul>
				</dd>
			</dl>
			
			<dl class="block" id="arc_list">
				<dt>archives</dt>
				<dd>
					<ul>
						<?php
						$the_year = 0;
						foreach($blog_archives as $arcy) {
							$year = $arcy->year;
							if($year == $the_year) {
								continue;
							} else {
						?>
						<li class="arc_year"><a href="javascript:;"><?php echo($year . '年'); ?></a>
							<ul>
								<?php
								foreach($blog_archives as $arc) {
									if($arc->year == $year) {
								?>
								<li><a href="<?php echo('/' . $blogger_uri . '/archive/' . $arc->year . '/' . $arc->month); ?>"><?php echo($arc->year . '年' . $arc->month . '月：' . $arc->num . '篇'); ?></a></li>
								<?php
									}
								}
								?>
							</ul>
						</li>
						<?php
							}
							$the_year = $year;
						}
						?>
					</ul>
				</dd>
			</dl>
			
			<dl class="block">
				<dt>links</dt>
				<dd>
					<ul>
						<?php foreach($links as $lk) { ?>
						<li>
							<a rel="friend" href="<?php echo($lk->url); ?>" target="_blank"><?php echo(htmlspec($lk->title)); ?></a>
							<div class="link_desc"><?php echo(htmlspec($lk->description)); ?></div>
						</li>
						<?php } ?>
					</ul>
				</dd>
			</dl>
			
			<dl class="block">
				<dt>statistics</dt>
				<dd>
					<ul>
						<li>网志数：<?php echo($blog_info->entry_num); ?></li>
						<li>评论数：<?php echo(is_null($blog_info->comment_num) ? '0' : $blog_info->comment_num); ?></li>
					</ul>
				</dd>
			</dl>
		</div><!-- /side -->
		<div class="z"></div>
	
	</div><!-- /body -->
	
	<!-- footer -->
	<?php require('common_footer.php'); ?>
	<!-- /footer -->
	
</div><!-- /wrapper -->

<!-- Common Widgets -->
<?php require('common_widgets.php'); ?>
<!-- /Common Widgets -->

<!-- JS -->
<script type="text/javascript" src="/js/3rd/jquery.pack.js"></script>
<script type="text/javascript" src="/js/3rd/jqModal.js"></script>
<script type="text/javascript" src="/js/3rd/json2.js"></script>
<script type="text/javascript">
<!--
var g_userSiteRoot = "<?php echo('/' . $blogger_uri); ?>";
// -->
</script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
<!--
<?php if($show_my_emotag) { ?>

function loadEmoTagList(pg) {
	$("#emoTagsWrapper").load(g_userSiteRoot + "/mgmt/emotag/" + pg, {
		"R": Math.random()
	}, function() {
		var pagingInfo = $("#hidEmoTagPaging").val();
		pagingInfo = pagingInfo.split("|");
		if(pagingInfo[1] == "1/0") {
			$("#emoTagPagingPanel").hide();
		} else {
			prevPg = pagingInfo[0];
			$("#emoTagPagingPanel span").text(pagingInfo[1]);
			nextPg = pagingInfo[2];
		}
		loadEmoTagPageDone = true;
	});
}

<?php } ?>

$(document).ready(function() {
	registerCommonEvents();
	
	// toggle archive (year) list
	$("#arc_list li.arc_year a").click(function() {
		$(this).parent().find("ul").toggle();
	});
	
	<?php if($show_my_emotag) { ?>
	
	$("#emoTagPagingPanel a").click(function() {
		if(!loadEmoTagPageDone) {
			return;
		}
		var way = $(this).attr("rel");
		$("#emoTagPagingPanel span").text("Loading...");
		if(way == "prev") {
			loadEmoTagList(prevPg);
		} else if(way == "next") {
			loadEmoTagList(nextPg);
		}
	});
	
	loadEmoTagList(0);
	
	<?php } ?>

	<?php require('common_skin_adapters.php'); ?>

});
// -->
</script>
<!-- /JS -->

</body>
</html>